﻿using Ivory;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Ivory.GUI;
using Ivory.Libs;
using CrystalCore;
using System;

namespace Barva
{
    public class MainMenu : MainMenuScreen
    {
        //Fields
        private Texture2D _Background;
        private GUI MenuGUI;

        //Construct
        public MainMenu(Game game)
            : base(game)
        {

        }

        //Methods
        public void CreateButton(string id, string text, Vector2 position, Action onClick)
        {
            TextButton temp = new TextButton(Game, Resources.Fonts["menu"], text, position);            
            temp.ID = id;
            temp.LeftClicked += delegate { onClick(); };

            temp.LoadComponent();
            MenuGUI.AddComponent(temp);
        }

        public override void RenderMenu(SpriteBatch batch, GameTime time)
        {
            batch.Begin();

            batch.Draw(_Background, Manager.WindowRect, Color.White);
            MenuGUI.DrawGUI(batch, time);

            batch.End();
        }
        public override void UpdateMenu(GameTime time, InputControl input)
        {
            MenuGUI.UpdateGUI(input, time);
        }

        public override bool LoadAssets()
        {
            _Background = Load<Texture2D>("graphics/menubackground");
            MenuGUI = new GUI();

            CreateButton("b1", "1/ Render Test 1", new Vector2(10, 10), () => { Manager.SwitchToGameScreen(RenderTest01.Key); });
            CreateButton("b2", "2/ Render Test 2", new Vector2(10, 50), () => { Manager.SwitchToGameScreen(RenderTest02.Key); });
            CreateButton("b3", "3/ Selection Test 1", new Vector2(10, 90), () => { Manager.SwitchToGameScreen(SelectionTest.Key); });
            CreateButton("b4", "4/ Level Test", new Vector2(10, 130), () => { Manager.SwitchToGameScreen(LevelTest.Key); });
            CreateButton("b5", "5/ Pathing Test", new Vector2(10, 170), () => { Manager.SwitchToGameScreen(PathingTest.Key); });
            CreateButton("b6", "6/ Camera Test", new Vector2(10, 210), () => { Manager.SwitchToGameScreen(CameraTest.Key); });

            CreateButton("b7", "7/ Pathfinding Demo Bsic", new Vector2(200, 10), () => { Manager.SwitchToGameScreen(PathfindingTestBasic.Key); });
            CreateButton("b8", "8/ Pathfinding Demo Adv", new Vector2(200, 50), () => { Manager.SwitchToGameScreen(PathfindingTestAdv.Key); });

            return true;
        }
    }
}
